package java8.chapter11.test;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class AsyncShopClient {

	public static void main(String[] args) {
		AsyncShop shop = new AsyncShop("BestShop");
		long start = System.nanoTime();
		Future<Double> futurePrice = shop.getPrice("myPhone");
		long incocationTime = ((System.nanoTime() - start) / 1_000_000);
		System.out.println("Invocation returned after " + incocationTime + " msecs");
		try {
			System.out.println("Price is " + futurePrice.get());
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		} catch (ExecutionException e) {
			throw new RuntimeException(e);
		}
		long retrivalTime = ((System.nanoTime() - start) / 1_000_000);
		System.out.println("Price returned after " + retrivalTime + " msecs");
	}

}